package com.ding.custommanagersys.controller;

import com.ding.custommanagersys.entity.User;
import com.ding.custommanagersys.vo.InitConfigVo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.*;

/**
 * @author Miles
 * @description: 用来初始化 layui的init文件
 * @date 2023/4/21 13:33
 **/
@RestController
public class LayuiAdminInitController {

    @RequestMapping("layui/init")
    public InitConfigVo init(HttpSession session){
        InitConfigVo initConfigVo;

        User user = (User) session.getAttribute("user");
        String username = user.gettUsername();
        if("admin".equals(username)){
            initConfigVo = inioByAdmin();
        }else{
            initConfigVo = inioByOther();
        }

        return initConfigVo;
    }

    //初始化 管理员的账号页面
    private InitConfigVo inioByAdmin(){
        InitConfigVo initConfigVo = new InitConfigVo();
        Map<String,String> homeInfo = new LinkedHashMap<>();
        homeInfo.put("title","首页");
        homeInfo.put("href","welcome");
        initConfigVo.setHomeInfo(homeInfo);

        Map<String,String> logoInfo = new LinkedHashMap<>();
        logoInfo.put("title","客户管理系统");
        logoInfo.put("image","layuimini/images/logo.png");
        logoInfo.put("href","");
        initConfigVo.setLogoInfo(logoInfo);

        List<Map<String,Object>> menuInfo = new ArrayList<>();
        Map<String,Object> menuInfoMap = new LinkedHashMap<>();
        menuInfoMap.put("title","客户管理");
        menuInfoMap.put("icon","fa fa-address-book");
        menuInfoMap.put("href","");
        menuInfoMap.put("target","_self");

        List<Map<String,Object>> child = new ArrayList<>();
        Map<String,Object> child1Map = new LinkedHashMap<>();
        child1Map.put("title","地区信息");
        child1Map.put("href","areaTable");
        child1Map.put("icon","fa fa-window-maximize");
        child1Map.put("target","_self");
        child.add(child1Map);

        Map<String,Object> child2Map = new LinkedHashMap<>();
        child2Map.put("title","客户管理");
        child2Map.put("href","");
        child2Map.put("icon","fa fa-home");
        child2Map.put("target","_self");

        List<Map<String,Object>> childTwo = new ArrayList<>();
        Map<String,Object> child21Map = new LinkedHashMap<>();
        child21Map.put("title","会员等级管理");
        child21Map.put("href","memberTable");
        child21Map.put("icon","fa fa-sort-amount-desc");
        child21Map.put("target","_self");
        childTwo.add(child21Map);

        Map<String,Object> child22Map = new LinkedHashMap<>();
        child22Map.put("title","客户管理");
        child22Map.put("href","customTable");
        child22Map.put("icon","fa fa-users");
        child22Map.put("target","_self");
        childTwo.add(child22Map);

        child2Map.put("child",childTwo);
        child.add(child2Map);

        Map<String,Object> child3Map = new LinkedHashMap<>();
        child3Map.put("title","发送邮件");
        child3Map.put("href","sendMsg");
        child3Map.put("icon","fa fa-send-o");
        child3Map.put("target","_self");
        child.add(child3Map);

        menuInfoMap.put("child",child);
        menuInfo.add(menuInfoMap);
        initConfigVo.setMenuInfo(menuInfo);

        return initConfigVo;
    }

    //初始化 非管理员的登录页面
    private InitConfigVo inioByOther() {

        InitConfigVo initConfigVo = new InitConfigVo();
        Map<String,String> homeInfo = new LinkedHashMap<>();
        homeInfo.put("title","首页");
        homeInfo.put("href","welcome");
        initConfigVo.setHomeInfo(homeInfo);

        Map<String,String> logoInfo = new LinkedHashMap<>();
        logoInfo.put("title","客户管理系统");
        logoInfo.put("image","layuimini/images/logo.png");
        logoInfo.put("href","");
        initConfigVo.setLogoInfo(logoInfo);

        List<Map<String,Object>> menuInfo = new ArrayList<>();
        Map<String,Object> menuInfoMap = new LinkedHashMap<>();
        menuInfoMap.put("title","我的信息");
        menuInfoMap.put("icon","fa fa-address-book");
        menuInfoMap.put("href","");
        menuInfoMap.put("target","_self");

        List<Map<String,Object>> child = new ArrayList<>();
        Map<String,Object> child1Map = new LinkedHashMap<>();
        child1Map.put("title","我的信息");
        child1Map.put("href","userAdmin");
        child1Map.put("icon","fa fa-user");
        child1Map.put("target","_self");
        child.add(child1Map);

        Map<String,Object> child3Map = new LinkedHashMap<>();
        child3Map.put("title","我的邮箱");
        child3Map.put("href","userEmail");
        child3Map.put("icon","fa fa-envelope");
        child3Map.put("target","_self");
        child.add(child3Map);

        menuInfoMap.put("child",child);
        menuInfo.add(menuInfoMap);
        initConfigVo.setMenuInfo(menuInfo);

        return initConfigVo;
    }

}
